<?php
defined( '_BOOTSTRAP' ) or die('<center>Dostęp pośredni jest<br><b>ZABRONIONY</b></center>');

include('./stderr.php');
include('./library/globals.php');
include('./library/database.php');
$database = new database('localhost', 'pstrychacz', 'szpaner1', 'poi', '3306');
$database->setCharacter('utf8');

session_start();
function isLoggedIn()
{
   if( isset($_SESSION['login']))
   {
      return $_SESSION['login'];
   }
   return 0;
}

function head()
{
   if (isset($_GET['cmd']))
   {
      if($_GET['cmd'] == 'login')
      {
         global $database;
         $login = mysql_real_escape_string( $_POST['login'] );
         $pass = mysql_real_escape_string( $_POST['pass'] );
         $query = "SELECT * FROM users WHERE login='".$login."' AND pass=sha1('".$pass."') AND active = 1 LIMIT 1";
         $database->query($query);
         if($r=@mysql_fetch_array($database->result))
         {
            $_SESSION['login'] = $r['rights'];
            $_SESSION['ID'] = $r['ID'];
            return;
         }
         else
         {
            $_SESSION['login'] = 0;
            return;
         }
      }
      if($_GET['cmd'] == 'logout')
      {
         unset($_SESSION['login']);
         unset($_SESSION['ID']);
      }
   }
}

?>
